const db = require("./database.js")

async function selectNewsList() {
  return new Promise((resolve, reject) => {
    db.all("select * from news", (err, rows) => {
      if (err) {
        reject(err);
      } else {
        resolve(rows);
      }
    });
  })
}

async function selectNewsByNewsId(news_id) {
  return new Promise((resolve, reject) => {
    const sql = 'select * from news where news_id = ?'
    db.get(sql, [news_id], (err, row) => {
      if (err) {
        reject(err);
      } else {
        resolve(row);
      }
    })
  });
}

module.exports = {
  selectNewsList,
  selectNewsByNewsId
}
